<template>
	<view class="loginBox">
		<view class="logoBox">
			<image src="./img/logo.jpg" class="logo" mode="aspectFit"></image>
		</view>
		<view class="btn">
			<button type="primary" @click="getuserinfo">微信登录</button>
		</view>
	</view>
</template>

<script>
	import {
		TOKENNAME
	} from '@/config/app';
	export default {
		data() {
			return {
			}
		},
		mounted() {
			if(this.$Cache.get(TOKENNAME)){
				uni.redirectTo({
					url:`/pages/index/index`
				})
			}
		},
		methods: {
			getuserinfo(res){
				if(this.$Cache.get('appId')){
					const query = new URLSearchParams(window.location.search);
					const redirect = query.get('redirect');
					const temp=decodeURIComponent(redirect).includes('/pages/login/index')?'/':redirect
					const host=window.location.protocol + "//" + window.location.host
					let url=host+temp;
					window.location.href=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.$Cache.get('appId')}&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
				}
			}
		},
	}
</script>

<style lang="scss">
.loginBox{
	height: auto;
	overflow: hidden;
	.logoBox{
		text-align: center;
		height: auto;
		overflow: hidden;
		margin-top: 100px;
		.logo{
			width: 120px;
			height: 120px;
		}
	}
	.btn{
		position: fixed;
		bottom: 200px;
		left: 0;
		right: 0;
		padding: 0 40px;
	}
}
</style>
